﻿Type=Activity
Version=5.8
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.

End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.

	Private lstData As List
	Private ulv As UltimateListView
	Private lbltitle As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
	'Do not forget to load the layout file created with the visual designer. For example:
	Activity.LoadLayout("layevallist")
	initviews
End Sub
Private Sub initviews
	Dim nh As Int=80dip
	lbltitle.Text="新闻列表"
	lstData.Initialize
	ulv.AddLayout("itemnews","ui_LayoutCreator","news_ContentFiller",nh,True)
	reqNewsList
End Sub
Private Sub reqNewsList
	comm.showProgress("正在获取新闻列表")
	ParseHelper.doGetReq(Me,"news",comm.getApi(comm.apiIdx.REQNEWSLIST),Null)
End Sub
Sub JobDone(thj As HttpJob)
	ProgressDialogHide
	If thj.Success Then
		Dim str As String=thj.GetString
		Dim nr As netRes=ParseHelper.getStatusData(str)
		If nr.nCode=200 Then
			parseNews(str)
		Else
			comm.TL("错误:"&nr.sData)
		End If
	Else
		comm.TL("网络错误:"&thj.ErrorMessage)
	End If
	thj.Release
End Sub
Private Sub parseNews(str As String)
	Dim parser As JSONParser 
	parser.Initialize(str) 
	Dim root As Map = parser.NextObject 
	Dim data As List = root.Get("data") 
	lstData.Clear
	For Each coldata As Map In data 
'	    Dim image As String = coldata.Get("image") 
'	    Dim class_id As String = coldata.Get("class_id") 
'	    Dim name As String = coldata.Get("name") 
	    Dim list As List = coldata.Get("list") 
	    For Each collist As Map In list 
	        lstData.Add(collist)
	    Next 
	Next 
'	Dim status As String = root.Get("status") 
	ulv.BulkAddItems(lstData.Size,"itemnews",0)
	
End Sub
Sub news_ContentFiller(ItemID As Long, LayoutName As String, LayoutPanel As Panel, Position As Int)
	Dim collist As Map=lstData.Get(ItemID)
	Dim image As String =comm.combinPic(collist.Get("image"))
    Dim title As String = collist.Get("title") 
	Dim p As Panel=LayoutPanel.GetView(0)
	Dim p2 As Panel=p.GetView(0)
	Dim iv As BetterImageView=p2.GetView(0)
	comm.loadimg(image,iv)
	Dim lbl As Label=p.GetView(1)
	lbl.Text=title
End Sub
Sub ui_LayoutCreator(LayoutName As String, LayoutPanel As Panel)
	LayoutPanel.LoadLayout(LayoutName)
End Sub
Sub ulv_ItemClick(ItemID As Long, Position As Int, ClickedPanel As Panel)
	Dim m As Map=lstData.Get(ItemID)
	Dim content_id As String = m.Get("content_id") 
	comm.TL("content_id:"&content_id)
End Sub
'Sub filldata
'	Dim nh As Int=80dip
'	For i=0 To 5
'		clv1.Add(CreateNewsItem("新闻"&Rnd(1,999),100%x,nh,i),nh,i)
'		clv2.Add(CreateNewsItem("新闻"&Rnd(1,999),100%x,nh,i),nh,i)
'		clv3.Add(CreateNewsItem("新闻"&Rnd(1,999),100%x,nh,i),nh,i)
'		clv4.Add(CreateNewsItem("新闻"&Rnd(1,999),100%x,nh,i),nh,i)
'	Next
'End Sub
Sub clv1_ItemClick (Index As Int, Value As Object)
	callwebview("http://news.qq.com/a/20160324/001316.htm")
End Sub
Sub clv2_ItemClick (Index As Int, Value As Object)
	callwebview("http://news.qq.com/a/20160324/001316.htm")
End Sub
Sub clv3_ItemClick (Index As Int, Value As Object)
	callwebview("http://news.qq.com/a/20160324/001316.htm")
End Sub
Sub clv4_ItemClick (Index As Int, Value As Object)
	callwebview("http://news.qq.com/a/20160324/001316.htm")
End Sub
Private Sub callwebview(u As String)
	Dim uu As wvUrl
	uu.Initialize
	uu.Url=u
	comm.startWV(uu)
End Sub
Private Sub CreateNewsItem(str As String,w As Int,h As Int,i As Int) As Panel
	Dim p As Panel
	p.Initialize("")
	Activity.AddView(p,0,0,w,h)
	p.LoadLayout("itemnews")
'	itemnewsimgbiv.Bitmap=LoadBitmap(File.DirAssets,"test_myheader.jpg")
'	itemnewstitle.Text=str
	p.RemoveView
	Return p
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub ivback_Click
	Activity.Finish
End Sub